package com.yjf.ljr.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RadioButton;

import com.yjf.ljr.R;
import com.yjf.ljr.adapter.ViewPagerAdapter;
import com.yjf.ljr.util.SPreferences;

public class WelcomeActivity extends IjActivity {

	private RadioButton[] mRbPoint = new RadioButton[4];

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setVerify(false);
		
		dismissProgressDialog();
		setContentView(R.layout.activity_welcome);
		for (int i = 0; i < 4; i++) {
			int id = getResources().getIdentifier("rbPoint_welcome" + i, "id", getPackageName());
			mRbPoint[i] = (RadioButton) findViewById(id);
		}

		ViewPager vpContent = (ViewPager) findViewById(R.id.vpContent_welcome);
		List<View> views = new ArrayList<View>();
		for (int i = 0; i < 4; i++) {
			if (i < 3) {
				ImageView img = new ImageView(this);
				img.setScaleType(ScaleType.FIT_XY);
				int id = getResources().getIdentifier("welcome_bg" + (i + 1), "drawable", getPackageName());
				img.setImageResource(id);
				views.add(img);
			} else {
				LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
				View view = inflater.inflate(R.layout.welcome_item, null);
				Button mBtnEnter = (Button) view.findViewById(R.id.btnEnter_welcome);
				mBtnEnter.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						SPreferences.setFirstRun(mContext);
						startActivity(new Intent(mContext, GroupActivity.class));
						finish();
					}
				});
				views.add(view);
			}
		}
		ViewPagerAdapter adapter = new ViewPagerAdapter(views);
		vpContent.setAdapter(adapter);
		vpContent.setOnPageChangeListener(pageChangeListener);

	}

	OnPageChangeListener pageChangeListener = new OnPageChangeListener() {

		@Override
		public void onPageSelected(int position) {
			mRbPoint[position].setChecked(true);
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {

		}

		@Override
		public void onPageScrollStateChanged(int arg0) {

		}
	};

	public boolean onFling(android.view.MotionEvent e1, android.view.MotionEvent e2, float velocityX, float velocityY) {
		return false;
	};
}
